<!DOCTYPE html>
<html lang="en">
<head>
    <title>{dede:global.cfg_webname/}</title>
    {dede:include filename="common_head.htm"/}
</head>
<body>
    <div class="main-wrap index-wrap about-wrap popup-wrap">
        <div class="popup-wrap h100 over-ys">
            <div class="popup-content flex ccc pt-2 pb-2">
                <div class="form-content-wrap w100">
                    <div class="popup-title text-c">Settlement Apply</div>
                    <div class="form-con-wrap">
                        <form id="apply-form">
                            <ul class="popup-form-wrap apply-form-wrap w100">
                                <li class="form-item apply-form-item flex rcs">
                                    <div class="form-item-label">Enterprise Name:</div>
                                    <input name="company" id="company" type="text" class="form-item-input" />
                                </li>
                                <li class="form-item apply-form-item apply-form-item-text flex rcs">
                                    <div class="form-item-label">Company Profile:</div>
                                    <textarea name="profile" id="profile" class="form-item-input form-item-textarea"></textarea>
                                </li>
                                <li class="form-item apply-form-item flex rcs">
                                    <div class="form-item-label">Relevant Qualifications:</div>
                                    <input name="qualification" id="qualification" type="text" class="form-item-input" />
                                </li>
                                <li class="form-item apply-form-item flex rcs">
                                    <div class="form-item-label">Contacts:</div>
                                    <input name="contact" id="contact" type="text" class="form-item-input" />
                                </li>
                                <li class="form-item apply-form-item flex rcs">
                                    <div class="form-item-label">Contact Information:</div>
                                    <input name="mobile" id="mobile" type="text" class="form-item-input" />
                                </li>
                            </ul>
                        </form>
                        <div class="error-tips-wrap">
                            <div class="error-tips"></div>
                        </div>
                    </div>
                    <div class="btn-wrap flex rcc">
                        <div class="flex ccc cur-p btn-item cancel-btn-item" onclick="closePopup();">Cancel</div>
                        <div class="flex ccc cur-p btn-item submit-btn-item" onclick="submitApply();">Determine</div>
                    </div>
                </div>
                <div class="result-content-wrap flex ccc none text-c">
                    <div class="pic-wrap pos-a close-btn-item cur-p" onclick="closePopup();">
                        <img src="{dede:global.cfg_templets_skin/}/icon/icon_close.png" alt="" class="pic-img btn-icon" />
                    </div>
                    <img src="{dede:global.cfg_templets_skin/}/icon/icon_success.png" alt="" class="pic-img result-img" />
                    <div class="result-title">Successful Application</div>
                </div>
            </div>
        </div>
        {dede:include filename="common_script.htm"/}
    </div>
    
    <script>
        
        // 提交申请
        function submitApply() {
            var popupWrap = $('.popup-wrap');
            var formWrap = $('.form-content-wrap');
            var resultWrap = $('.result-content-wrap');

            var _company = $('#company'),
                _companyVal = _company.val();

            var _profile = $('#profile'),
                _profileVal = _profile.val();

            var _qualification = $('#qualification'),
                _qualificationVal = _qualification.val();

            var _contact = $('#contact'),
                _contactVal = _contact.val();

            var _mobile = $('#mobile'),
                _mobileVal = _mobile.val();

            var _other = $('#other'),
                _otherVal = _other.val();

            var _errorWrap = $('.error-tips-wrap'),
                _errorTips = _errorWrap.find('.error-tips');

            var _dateStr = new Date(),
                _currentDate = _dateStr.Format("yyyy-MM-dd hh:mm:ss");


            if (_companyVal == '') {
                _errorWrap.addClass('cur');
                _errorTips.text('* Enterprise name cannot be empty');
                _company.focus();
                return false;
            }

            if (_profileVal == '') {
                _errorWrap.addClass('cur');
                _errorTips.text('* Company profile cannot be blank');
                _profile.focus();
                return false;
            }

            if (_qualificationVal == '') {
                _errorWrap.addClass('cur');
                _errorTips.text('* Relevant qualification cannot be empty');
                _qualification.focus();
                return false;
            }

            if (_contactVal == '') {
                _errorWrap.addClass('cur');
                _errorTips.text('* Contact cannot be empty');
                _contact.focus();
                return false;
            }

            if (_mobileVal == '') {
                _errorWrap.addClass('cur');
                _errorTips.text('* Contact information cannot be empty');
                _mobile.focus();
                return false;
            } else if (!/^1[0-9]{10}/.test(_mobileVal)) {
                _errorWrap.addClass('cur');
                _errorTips.text('* Incorrect format of mobile phone number');
                _mobile.focus();
                return false;
            }


            var dataString =
                'company=' + _companyVal +
                '&profile=' + _profileVal +
                '&qualification=' + _qualificationVal +
                '&contact=' + _contactVal +
                '&mobile=' + _mobileVal +
                '&create_time=' + _currentDate +
                '&action=post' +
                '&diyid=2&do=2' +
                '&dede_fields=company,text;profile,multitext;qualification,text;contact,text;mobile,text;create_time,text' +
                '&dede_fieldshash=decd20b0934da5a74dab6dbd7024a2fe';

            layer.msg('Are you sure you want to submit the application?', {
                time: 0,
                btn: ['Determine', 'Cancel'],
                yes: function(index) {
                    layer.close(index);
                    $.ajax({
                        type: "POST",
                        url: "/plus/diy.php",
                        data: dataString,
                        success: function(data) {
                            $('#apply-form')[0].reset();
                            popupWrap.removeClass('over-ys').addClass('flex ccc');
                            formWrap.addClass('none');
                            resultWrap.addClass('cur');
                            _errorWrap.removeClass('cur');
                        }
                    });
                }
            });
            return false;
            
        }

        // 关闭弹窗
        function closePopup() {
            console.log('1---->', 1);
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
            layer.closeAll();
        }

    </script>
</body>
</html>